<?php
include 'admin_config_lib.php';

if ($s_Action == 'insert') {
    
} else if ($s_Action == 'update') {
    $db_query  = db_get_query($a_tablecolumns_namhoa_system_option) . " where option_id = '$f_option_id' limit 1";
    $db_result = db_query($db_conn, $db_query);

    if (!($d_system_option = db_fetch($db_result))) {
        raise_error('Kiểm tra lại thông tin!');
    }
}
?>
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
    <h3>Lần Kiểm Tra</h3>
</div>
<form id="form_examtime" class="horizontal-form" action="admin_config_execute.php?action=<?= $s_Action ?>-examtime" method="post">
    <div class="modal-body">
        <div class="portlet-body">
            <div class="alert alert-error hide">
                <button class="close" data-dismiss="alert"></button>
                Kiểm tra lại thông tin bên dưới.
            </div>
            <div class="row-fluid">
                <div class="span4">
                    <div class="control-group">
                        <label class="control-label">Ký Hiệu</label>
                        <div class="controls">
                            <input type="hidden" value="<?= $d_system_option->option_id ?>" name="option_id" />
                            <input type="hidden" value="LAN_KIEM_TRA" name="option_type" />
                            <input type="text" value="<?= $d_system_option->option_key ?>" placeholder="LAN_1" class="m-wrap span12" name="option_key" id="option_key" style="text-transform: uppercase" <?= $s_Action == 'update' ? 'readonly="readonly"' : ''?>>
                        </div>
                    </div>
                </div>
                <div class="span8">
                    <div class="control-group">
                        <label class="control-label">Tên</label>
                        <div class="controls">
                            <input type="text" value="<?= $d_system_option->option_data ?>" placeholder="Lần 1" class="m-wrap span12" name="option_data">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <button type="button" data-dismiss="modal" class="btn">Thoát</button>
        <button class="btn blue" type="submit"><i class="icon-ok"></i> <?= $s_Action == 'insert' ? 'Thêm' : 'Lưu' ?></button>
    </div>
</form>

<script type="text/javascript">
    var validate_examtime = function() {

        var frm_examtime = $('#form_examtime');
        var err_examtime = $('.alert-error', frm_examtime);

        frm_examtime.validate({
            errorElement: 'span', //default input error message container
            errorClass: 'help-inline', // default input error message class
            focusInvalid: false, // do not focus the last invalid input
            ignore: "",
            rules: {
                option_key: {
                    minlength: 1,
                    required: true
                },
                option_data: {
                    minlength: 2,
                    required: true
                }
            },
            messages: {
                option_key: {
                    minlength: 'Tối thiểu 1 ký tự',
                    required: 'Bắt buộc nhập'
                },
                option_data: {
                    minlength: 'Tối thiểu 2 ký tự',
                    required: 'Bắt buộc nhập'
                }
            },
            invalidHandler: function (event, validator) { //display error alert on form submit              
                err_examtime.show();
                App.scrollTo(err_examtime, -200);
            },
            highlight: function (element) { // hightlight error inputs
                $(element)
                .closest('.help-inline').removeClass('ok'); // display OK icon
                $(element)
                .closest('.control-group').removeClass('success').addClass('error'); // set error class to the control group
            },
            unhighlight: function (element) { // revert the change done by hightlight
                $(element)
                .closest('.control-group').removeClass('error'); // set error class to the control group
            },
            success: function (label) {
                label
                .closest('.control-group').removeClass('error').addClass('success').end()
                .remove(); // set success class to the control group
            },
            submitHandler: function (form) {
                err_examtime.hide();
                form.submit();
            }
        });
    }
    
    validate_examtime();
</script>